package org.example.network.ex4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //TCP协议，接收数据
        //1.创建对象ServerSocket
        ServerSocket ss = new ServerSocket(10000);
        //2.监听客户端的链接
        Socket socket = ss.accept();
        //3.从连接通道中获取输入流读取数据
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        char[] cs = new char[1024];
        int len;
        while ((len = br.read(cs)) != -1){
            System.out.print(new String(cs, 0, len));
        }
        //4.释放资源
        socket.close();
        ss.close();
    }
}
